<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button>停止</button>
    <script>

        // 设置定时器
       let timer = setInterval(() => {
            console.log('定时器执行了');
            
        }, 1000);
      
        
        // 停止定时器
        let but = document.querySelector('button')
        but.onclick = function(){
            console.log(122);
            // 停止定时器
            // clearInterval(定时器名称)
            clearInterval(timer)
            
        }
    </script>
</body>
</html>